/**
 * 
 */
package messaage;

import utils.LogHelper;

/**
 * @author Olga
 * 
 */
public class AddedForumMsg extends Message {

	protected String forumID;
        protected String subject;
        protected String friendship;

	/**
	 * 
	 */
	public AddedForumMsg(String whoAddedMsg, String forumID, String subject, String friendship) {
		super.username = whoAddedMsg;
		this.forumID = forumID;
                this.subject = subject;
                this.friendship = friendship;
	}

        /** 
         *
         * parsing the msg string to ForumID and subject
         * @param msg has the following format:
         * "AddedForum\n<username>\n<forumID>\n<subject>\n\0"
         */
	public AddedForumMsg(String msg){
		String[] splitted = msg.split("\n");
                if (splitted.length < 5){
                    LogHelper.instance().log("Parsing AddedForumMsg failed becuse msg has a wrong format");
                    return;
                }
                this.username = splitted[1];
                this.friendship = splitted[2];
                this.forumID = splitted[3];
                this.subject = splitted[4];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see messaage.Message#toString()
	 */
	@Override
	public String toString() {
		String ans = "AddedForum\n"+this.username+"\n"+this.friendship+"\n"+this.forumID+"\n"+this.subject + "\n\0"; 
		return ans;
	}

    public int getForumID() {
        return Integer.parseInt(forumID);
    }

    public String getSubject() {
        return subject;
    }

    public boolean isFriend(){
        return this.friendship.equalsIgnoreCase("true");
    }

}
